import 'package:vista/shared/models/base_frame.dart';

/// 挑战投稿画面
/// 存储用户在主题挑战下发布的摄影图片，如摄影中的投稿作品般记录参与
class ChallengeSubmission extends BaseFrame {
  final String id; // 投稿ID
  final String challengeId; // 主题挑战ID
  final String authorId; // 作者ID
  final String image; // 摄影图片
  final int viewCount; // 访问次数
  final DateTime timestamp; // 发布时间

  const ChallengeSubmission({
    required this.id,
    required this.challengeId,
    required this.authorId,
    required this.image,
    this.viewCount = 0,
    required this.timestamp,
  });

  /// 从JSON创建挑战投稿画面
  factory ChallengeSubmission.fromJson(Map<String, dynamic> json) {
    return ChallengeSubmission(
      id: json['id'] as String,
      challengeId: json['challengeId'] as String,
      authorId: json['authorId'] as String,
      image: json['image'] as String,
      viewCount: json['viewCount'] as int? ?? 0,
      timestamp: DateTime.parse(json['timestamp'] as String),
    );
  }

  @override
  List<Object?> get props => [
    id,
    challengeId,
    authorId,
    image,
    viewCount,
    timestamp,
  ];

  @override
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'challengeId': challengeId,
      'authorId': authorId,
      'image': image,
      'viewCount': viewCount,
      'timestamp': timestamp.toIso8601String(),
    };
  }
}
